package rab.security.trap;

//import ApplicationInfo;
//import PackageInfo;
//import PackageManager;
//import ResolveInfo;
import android.app.Activity;
import android.os.Bundle;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.Manifest.permission;
import android.content.Intent;
import android.content.Context;
import android.content.pm.*;
//import android.content.pm.ResolveInfo;
//import  android.content.pm.PackageInfo;
//import android.content.pm.PackageManager;
//import android.content.pm.ApplicationInfo;
import android.content.ContentResolver;
import android.content.Intent;
import android.net.Uri;
import android.app.Activity;
import android.app.PendingIntent;
//import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.content.BroadcastReceiver;


import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

public class SecurityStopActivity extends ListActivity {
    int res1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);
        //      p = new Permission();
        /*
         * This example uses an ArrayAdapter to fill the ListActivity with
         * specific values. The ArrayAdapter needs a reference to a layout item
         * representing a TextView and a String array with the values to be
         * shown. The TextView is defined in layout resource
         * res/layout/list_item.xml
         */
        final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        final List<ResolveInfo> pkgAppsList = getPackageManager().queryIntentActivities( mainIntent, 0);
        final List<String> apps = new ArrayList();
        
//        for (ResolveInfo inf : pkgAppsList) {           
 //           apps.add(inf.resolvePackageName);
  //          apps.add(inf.activityInfo.targetActivity);
    //    }
        PackageManager pm = getPackageManager();    
 //       final List<PackageInfo> pList = pm.getPreferredPackages (PackageManager.GET_ACTIVITIES);
 //       final List<String> apps = new ArrayList();
  //      apps.add("Start Packages");
  //      for (PackageInfo inf : pList) {           
 //           apps.add(inf.resolvePackageName);
    //        apps.add(inf.packageName);
      //  }
       
//        mContactsObserver = new ContactsObserver(mHandler);
//
        
 //       getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, mContactsObserver);     
        
        final List<ApplicationInfo> aList = pm.getInstalledApplications (0);
        apps.add("Start Applications");
        for (ApplicationInfo inf2 : aList) { 
            if (inf2.packageName == null) {
                    apps.add("**toString Name: " + inf2.toString());
                    }
                else  {
                    apps.add(inf2.packageName);
                    }
         }
       
       
        
        
        Log.v("DEBUG","Happy Days");
       
//       setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, FRUITS));
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, apps));
        /*
         * Retrieve the ListView.
         */
        ListView listView = getListView();
        /*
         * Set a click listener that will be invoked whenever an item from the
         * list has been selected.
         */
        listView.setOnItemClickListener(new OnItemClickListener() {
    
            
            /*
             * Callback that will be invoked whenever an item from the list has
             * been selected. 'parent' is the AdapterView where the click
             * happened. 'view' is the view within the AdapterView that was
             * clicked (this will be a view provided by the adapter). 'position'
             * is the position of the view in the adapter. 'id' is the row id of
             * the item that was clicked.
             */
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                /*
                 * Whenever an item of the ListActivity is selected, show an
                 * AlertDialog to inform which item was selected. The way the
                 * AlertDialog is built up is an example of a fluent interface.
                 */
                int res1, res;
                res1 = 123;
                String resMsg;
                
                resMsg = "Permissions:  ";
                PackageManager pm = getPackageManager();
                
                
                res1 = checkCallingPermission (android.Manifest.permission.BATTERY_STATS);
                
                AlertDialog.Builder builder = new AlertDialog.Builder(SecurityStopActivity.this);
                Log.v("DEBUG","We are here! built builder");
               
                String packageName = ((TextView) view).getText().toString();
                
                res = pm.checkPermission(android.Manifest.permission.ACCESS_CHECKIN_PROPERTIES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCESS_CHECKIN_PROPERTIES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCESS_COARSE_LOCATION\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.ACCESS_FINE_LOCATION,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCESS_FINE_LOCATION\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCESS_LOCATION_EXTRA_COMMANDS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.ACCESS_MOCK_LOCATION,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCESS_MOCK_LOCATION\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCESS_NETWORK_STATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.ACCESS_SURFACE_FLINGER,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCESS_SURFACE_FLINGER\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.ACCESS_WIFI_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCESS_WIFI_STATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.ACCOUNT_MANAGER,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ACCOUNT_MANAGER\n";
                    }

 /*               res = pm.checkPermission(android.Manifest.permission.ADD_VOICEMAIL,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "ADD_VOICEMAIL\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.AUTHENTICATE_ACCOUNTS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "AUTHENTICATE_ACCOUNTS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BATTERY_STATS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BATTERY_STATS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BIND_APPWIDGET,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BIND_APPWIDGET\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BIND_DEVICE_ADMIN,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BIND_DEVICE_ADMIN\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BIND_INPUT_METHOD,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BIND_INPUT_METHOD\n";
                    }

 /*               res = pm.checkPermission(android.Manifest.permission.BIND_REMOTEVIEWS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BIND_REMOTEVIEWS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BIND_TEXT_SERVICE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BIND_TEXT_SERVICE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BIND_VPN_SERVICE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BIND_VPN_SERVICE\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.BIND_WALLPAPER,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BIND_WALLPAPER\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BLUETOOTH,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BLUETOOTH\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BLUETOOTH_ADMIN,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BLUETOOTH_ADMIN\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BRICK,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BRICK\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BROADCAST_PACKAGE_REMOVED,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BROADCAST_PACKAGE_REMOVED\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BROADCAST_SMS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BROADCAST_SMS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BROADCAST_STICKY,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BROADCAST_STICKY\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.BROADCAST_WAP_PUSH,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "BROADCAST_WAP_PUSH\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CALL_PHONE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CALL_PHONE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CALL_PRIVILEGED,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CALL_PRIVILEGED\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CAMERA,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CAMERA\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CHANGE_COMPONENT_ENABLED_STATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CHANGE_CONFIGURATION,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CHANGE_CONFIGURATION\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CHANGE_NETWORK_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CHANGE_NETWORK_STATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CHANGE_WIFI_MULTICAST_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CHANGE_WIFI_MULTICAST_STATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CHANGE_WIFI_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CHANGE_WIFI_STATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CLEAR_APP_CACHE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CLEAR_APP_CACHE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CLEAR_APP_USER_DATA,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CLEAR_APP_USER_DATA\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "CONTROL_LOCATION_UPDATES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.DELETE_CACHE_FILES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "DELETE_CACHE_FILES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.DELETE_PACKAGES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "DELETE_PACKAGES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.DEVICE_POWER,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "DEVICE_POWER\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.DIAGNOSTIC,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "DIAGNOSTIC\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.DISABLE_KEYGUARD,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "DISABLE_KEYGUARD\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.DUMP,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "DUMP\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.EXPAND_STATUS_BAR,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "EXPAND_STATUS_BAR\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.FACTORY_TEST,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "FACTORY_TEST\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.FLASHLIGHT,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "FLASHLIGHT\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.FORCE_BACK,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "FORCE_BACK\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.GET_ACCOUNTS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "GET_ACCOUNTS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.GET_PACKAGE_SIZE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "GET_PACKAGE_SIZE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.GET_TASKS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "GET_TASKS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.GLOBAL_SEARCH,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "GLOBAL_SEARCH\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.HARDWARE_TEST,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "HARDWARE_TEST\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.INJECT_EVENTS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "INJECT_EVENTS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.INSTALL_LOCATION_PROVIDER,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "INSTALL_LOCATION_PROVIDER\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.INSTALL_PACKAGES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "INSTALL_PACKAGES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.INTERNAL_SYSTEM_WINDOW,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "INTERNAL_SYSTEM_WINDOW\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.INTERNET,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "INTERNET\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.KILL_BACKGROUND_PROCESSES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "KILL_BACKGROUND_PROCESSES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.MANAGE_ACCOUNTS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "MANAGE_ACCOUNTS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.MANAGE_APP_TOKENS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "MANAGE_APP_TOKENS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.MASTER_CLEAR,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "MASTER_CLEAR\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "MODIFY_AUDIO_SETTINGS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.MODIFY_PHONE_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "MODIFY_PHONE_STATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "MOUNT_FORMAT_FILESYSTEMS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "MOUNT_UNMOUNT_FILESYSTEMS\n";
                    }

 /*               res = pm.checkPermission(android.Manifest.permission.NFC,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "NFC\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.PERSISTENT_ACTIVITY,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "PERSISTENT_ACTIVITY\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.PROCESS_OUTGOING_CALLS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "PROCESS_OUTGOING_CALLS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.READ_CALENDAR,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_CALENDAR\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.READ_CONTACTS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_CONTACTS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.READ_FRAME_BUFFER,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_FRAME_BUFFER\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.READ_HISTORY_BOOKMARKS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_HISTORY_BOOKMARKS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.READ_INPUT_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_INPUT_STATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.READ_LOGS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_LOGS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.READ_PHONE_STATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_PHONE_STATE\n";
                    }

/*                res = pm.checkPermission(android.Manifest.permission.READ_PROFILE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_PROFILE\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.READ_SMS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_SMS\n";
                    }

 /*               res = pm.checkPermission(android.Manifest.permission.READ_SOCIAL_STREAM,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_SOCIAL_STREAM\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.READ_SYNC_SETTINGS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_SYNC_SETTINGS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.READ_SYNC_STATS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "READ_SYNC_STATS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.REBOOT,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "REBOOT\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.RECEIVE_BOOT_COMPLETED,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "RECEIVE_BOOT_COMPLETED\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.RECEIVE_MMS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "RECEIVE_MMS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.RECEIVE_SMS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "RECEIVE_SMS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.RECEIVE_WAP_PUSH,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "RECEIVE_WAP_PUSH\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.RECORD_AUDIO,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "RECORD_AUDIO\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.REORDER_TASKS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "REORDER_TASKS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.RESTART_PACKAGES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "RESTART_PACKAGES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SEND_SMS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SEND_SMS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_ACTIVITY_WATCHER\n";
                    }

/*                res = pm.checkPermission(android.Manifest.permission.SET_ALARM,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_ALARM\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.SET_ALWAYS_FINISH,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_ALWAYS_FINISH\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_ANIMATION_SCALE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_ANIMATION_SCALE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_DEBUG_APP,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_DEBUG_APP\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_ORIENTATION,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_ORIENTATION\n";
                    }

 /*               res = pm.checkPermission(android.Manifest.permission.SET_POINTER_SPEED,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_POINTER_SPEED\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_PREFERRED_APPLICATIONS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_PROCESS_LIMIT,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_PROCESS_LIMIT\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_TIME,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_TIME\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_TIME_ZONE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_TIME_ZONE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_WALLPAPER,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_WALLPAPER\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SET_WALLPAPER_HINTS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SIGNAL_PERSISTENT_PROCESSES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SIGNAL_PERSISTENT_PROCESSES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.STATUS_BAR,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "STATUS_BAR\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SUBSCRIBED_FEEDS_READ,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SUBSCRIBED_FEEDS_READ\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SUBSCRIBED_FEEDS_WRITE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SUBSCRIBED_FEEDS_WRITE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.SYSTEM_ALERT_WINDOW,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "SYSTEM_ALERT_WINDOW\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.UPDATE_DEVICE_STATS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "UPDATE_DEVICE_STATS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.USE_CREDENTIALS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "USE_CREDENTIALS\n";
                    }

 /*               res = pm.checkPermission(android.Manifest.permission.USE_SIP,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "USE_SIP\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.VIBRATE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "VIBRATE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WAKE_LOCK,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WAKE_LOCK\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WRITE_APN_SETTINGS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_APN_SETTINGS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WRITE_CALENDAR,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_CALENDAR\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WRITE_CONTACTS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_CONTACTS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_EXTERNAL_STORAGE\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WRITE_GSERVICES,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_GSERVICES\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WRITE_HISTORY_BOOKMARKS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_HISTORY_BOOKMARKS\n";
                    }

/*                res = pm.checkPermission(android.Manifest.permission.WRITE_PROFILE,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_PROFILE\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_SECURE_SETTINGS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WRITE_SETTINGS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_SETTINGS\n";
                    }

                res = pm.checkPermission(android.Manifest.permission.WRITE_SMS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_SMS\n";
                    }

 /*               res = pm.checkPermission(android.Manifest.permission.WRITE_SOCIAL_STREAM,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_SOCIAL_STREAM\n";
                    }
*/
                res = pm.checkPermission(android.Manifest.permission.WRITE_SYNC_SETTINGS,packageName);
                if (res == PackageManager.PERMISSION_GRANTED) {
                    resMsg = resMsg + "WRITE_SYNC_SETTINGS\n";
                    }

                
                
               PackageInfo pi;
               try {
                   pi = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES |
             
                        PackageManager.GET_GIDS | 
                        PackageManager.GET_CONFIGURATIONS | 
                        PackageManager.GET_INSTRUMENTATION | 
                        PackageManager.GET_PERMISSIONS | 
                        PackageManager.GET_PROVIDERS | 
                        PackageManager.GET_RECEIVERS |
                        PackageManager.GET_SERVICES | 
                        PackageManager.GET_SIGNATURES);  
                   if (pi.requestedPermissions != null) {
                       resMsg = resMsg + "--- Requested Permissions ---\n";
                       for (String x: pi.requestedPermissions){
                       
                           resMsg = resMsg + x + "\n";
                       }
                   }
              } catch (android.content.pm.PackageManager.NameNotFoundException e){
                   apps.add("Bad Package Name: " + packageName + "\n");
               }
                
                
//                builder.setTitle(android.Manifest.permission.ACCESS_COARSE_LOCATION).setMessage(res1)
//                .setCancelable(false).setPositiveButton("Ok", null);
                builder.setTitle("Selection: " + packageName).setMessage(resMsg)
                .setCancelable(false).setPositiveButton("Ok", null);
                /*
                 * Create and show the model AlertDialog.
                 */
                builder.create().show();
            }

        });
        
        
    }
}